package itv.java.web;

import itv.java.web.conf.Config;

import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

/**
 * @author : H-Thien
 * @comment :
 */
public class InitialServlet extends HttpServlet {
	private static final String PROPERTIES_FILE = File.separator + "WEB-INF"
			+ File.separator + "classes" + File.separator + "server.properties";

	/**
	 * @comment :
	 */
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		loadConfiguration(config);
	}

	/**
	 * @comment :
	 */
	private void loadConfiguration(ServletConfig config) {
		try {
			FileInputStream inputStream = new FileInputStream(config
					.getServletContext().getRealPath(PROPERTIES_FILE));
			Properties properties = new Properties();
			properties.load(inputStream);

			inputStream.close();

			Config serverConfig = Config.getInstance();
			serverConfig.setProperties(properties);
		} catch (Exception e) {
			System.err.println("Config Load Error:" + e);
		}
	}
}